﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceShooter.Common
{
    /// <summary>
    /// GameObject extends a DrawableGameObject by the possibility to manage health and damage.
    /// When the health is below zero, the object is destroyed.
    /// </summary>
    public abstract class GameObject : DrawableGameObject
    {
        public GameObject(IGameScreen gameScreen, string modelName)
            : base(gameScreen, modelName)
        {
        }

        public float MaximumHealth { get; protected set; }

        public float RemainingHealth { get; protected set; }

        public void ApplyDamage(float damagePoints)
        {
            this.RemainingHealth -= damagePoints;

            if (this.RemainingHealth < 0)
            {
                this.Explode();
            }
        }

        public void ApplyDamage(GameObject collisionPartner)
        {
            this.ApplyDamage(collisionPartner.DamageOnExplosion);

            if (this.RemainingHealth < 0)
            {
                  collisionPartner.DamageOnExplosion = -this.RemainingHealth;
            }
            else
            {
                //collisionPartner.DamageOnExplosion = 0;
            }
        }

        protected virtual void Explode()
        {
            this.RemoveFlag = true;
        }

        public float DamageOnExplosion { get; protected set; }
    }
}